#include "board.h"

#define DAC_OBUF_SIZE   576
#define BUFSZ   1024
#define SOUND_DEVICE_NAME    "sound0"    /* Audio 设备名称 */
static rt_device_t snd_dev;              /* Audio 设备句柄 */

/**
 * 48K stero sin
 */
const unsigned char hexData[96] = {
    0x00, 0x00, 0xB5, 0x10, 0x21, 0x21, 0xFC, 0x30, 0x00, 0x40, 0xEC, 0x4D, 0x82, 0x5A, 0x8D, 0x65,
    0xDA, 0x6E, 0x42, 0x76, 0xA3, 0x7B, 0xE8, 0x7E, 0xFF, 0x7F, 0xE8, 0x7E, 0xA3, 0x7B, 0x42, 0x76,
    0xDA, 0x6E, 0x8D, 0x65, 0x82, 0x5A, 0xEC, 0x4D, 0x00, 0x40, 0xFC, 0x30, 0x21, 0x21, 0xB5, 0x10,
    0x00, 0x00, 0x4B, 0xEF, 0xDF, 0xDE, 0x04, 0xCF, 0x00, 0xC0, 0x14, 0xB2, 0x7E, 0xA5, 0x73, 0x9A,
    0x26, 0x91, 0xBE, 0x89, 0x5D, 0x84, 0x18, 0x81, 0x00, 0x80, 0x18, 0x81, 0x5D, 0x84, 0xBE, 0x89,
    0x26, 0x91, 0x73, 0x9A, 0x7E, 0xA5, 0x14, 0xB2, 0x00, 0xC0, 0x04, 0xCF, 0xDF, 0xDE, 0x4B, 0xEF 
};

void audio_test(void)
{
   rt_err_t ret = RT_ERROR;
   uint32_t i = 65535;

   snd_dev = rt_device_find(SOUND_DEVICE_NAME);
   ret = rt_device_open(snd_dev, RT_DEVICE_OFLAG_WRONLY);
   if (ret == RT_EOK) {
      rt_kprintf("sound0 open successful\n");
   }

   while (i-- > 0)
   {
      rt_device_write(snd_dev, 0, hexData, 48*2);
   }

   rt_device_close(snd_dev);
}
MSH_CMD_EXPORT(audio_test, "audio_test");
